#include<bits/stdc++.h>
using namespace std;
int ans;
int p[200005];
int a[200005],c[200005];
int t;
long long n,man,pl;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    for(int o=1;o<=t;o++){
        cin>>n;
        memset(a,0,sizeof(a));
        for(int l=1;l<=n;l++){
            cin>>a[l];
        }
        memset(p,0,sizeof(p));
        memset(c,0,sizeof(c));
        while(p[0]==0){
            for(int i=1;i<=n;i++){
                for(int j=i-1;j>=1;j--){
                    if(p[i]==p[j]){
                        if(a[i]==a[j]){
                            c[i]=a[i];
                        }
                        else c[i]=0;
                        break;
                    }
                }
           }
            int k=n;
            while(p[k]==1) k--;
            p[k]=1;
            for(int i=k+1;i<=n;i++) p[i]=0;
            for(int i=1;i<=n;i++){
                pl+=c[i];
            }
            man=max(man,pl);
            pl=0;
        }
        cout<<man<<endl;
        man=0;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}

